package com.hyf.Test;

import com.alibaba.druid.pool.DruidDataSource;
import com.hyf.bean.Account;
import com.hyf.dao.AccountDao;
import com.hyf.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class Mytest {
    @Autowired
    Account account;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    AccountDao accountDao;
    @Autowired
    AccountService accountService;

    @Test
    public void test1(){
        System.out.println(account);
    }
    @Test
    public void selectAll(){
        String sql = "select * from account";
        RowMapper<Account> rm= new BeanPropertyRowMapper<>(Account.class);
        List<Account> query = jdbcTemplate.query(sql, rm);
        for (Account account11 : query) {
            System.out.println(account11);
        }
    }
    @Test
    public void accountDao(){
        accountDao.updateSubMoneyByName("lisi",4000);
    }
    @Test
    public void accountService(){
        accountService.transfer("wangwu","zhaoliu",6000);
    }

}
